﻿using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace BONSAI.Admin.UC
{
    public partial class ToursManager : System.Web.UI.UserControl
    {
        /*
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDropLoaiTours();
                BindStart();
            }
        }
        void BindDropLoaiTours()
        {
            ListItem list = new ListItem("Tất cả", "0");
            //DataTable table = type.LoaiTours_Get(0);
            //droptypetours.DataSource = table;
            //droptypetours.DataValueField = "ID";
            //droptypetours.DataTextField = "LoaiTours";
            //droptypetours.DataBind();
            var table = (new LoaiToursBO()).GetAll();

            foreach (var dto in table)
            {
                droptypetours.Items.Add(
                    new ListItem(
                        "(" + dto.ID + ")" + dto.LoaiTours,
                        dto.ID.ToString()));
            }
            droptypetours.Items.Insert(0, list);
        }
        public void BindStart()
        {
            //// delete all
            //if (Request.QueryString["zxc"] != null)
            //{
            //    if (Request.QueryString["zxc"].ToString() == "1qwertyuiop")
            //    {
            //        em.Trainee_Delete(0);
            //    }
            //}
            ////=============

            DataTable table = tours.Tours_GetAS(0, Int32.Parse(droptypetours.SelectedValue.ToString()),
                Int32.Parse(droptourshot.SelectedValue.ToString()),
                Int32.Parse(droptoursuuthich.SelectedValue.ToString()), 0, 0);
            GridView1.DataSource = table;
            GridView1.DataBind();

        }
        protected void lbcreate_Click(object sender, EventArgs e)
        {
            Response.Redirect("ToursUpdate.aspx");
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            BindStart();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string key = GridView1.DataKeys[e.RowIndex].Value.ToString();
            tours.Tours_Delete(Int32.Parse(key));
            BindStart();
            //tourstienich
            //ImageTours
            //toursfact
            //videotours
            //toursdichvu

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BindStart();
        }

        protected void btthietlap_Click(object sender, EventArgs e)
        {
            HtmlInputCheckBox check;
            bool res = false;
            foreach (GridViewRow row in GridView1.Rows)
            {
                check = (HtmlInputCheckBox)row.FindControl("checkbox");
                if (check.Checked)
                {
                    tours.Tours_Thietlap(Int32.Parse(check.Value), Int32.Parse(dropthietlaptourshot.SelectedValue),
                        Int32.Parse(dropthietlaptoursuuthich.SelectedValue));

                    res = true;
                }
            }
            if (res == false)
            {
                WebMBox.Show("Vui lòng chọn tours để thiết lập, Check checkbox để chọn tours.");
            }
            BindStart();
        }
        protected bool DisplayActive(bool active)
        {

            if (active)
            {
                return false;
            }

            return true;
        }

        protected bool DisplayDeActive(bool active)
        {
            if (active)
            {
                return true;
            }

            return false;
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string task = e.CommandName.ToString();
            string ID = e.CommandArgument.ToString();

            if (string.IsNullOrEmpty(ID))
            {
                return;
            }
            switch (task)
            {
                case "DisplayActive":
                    tours.Tours_UpdateActive(true, Convert.ToInt32(ID));
                    BindStart();
                    WebMBox.Show("tours hiển thị lên trang chủ .");
                    break;
                case "DisplayDeActive":
                    tours.Tours_UpdateActive(false, Convert.ToInt32(ID));
                    BindStart();
                    WebMBox.Show("tours không còn hiển thị lên trang chủ.");
                    break;
            }
        }*/
    }
}